home *** CD-ROM | disk | FTP | other *** search
- RealURL = {
- // hidden preferences...
- service: "",
- timeout: NaN,
-
- // private...
- request: null,
- timer: null,
-
- // what to display...
- display: {
- url: false,
- type: false,
- charset: false,
- size: false,
- title: false
- },
-
- pref: Components
- .classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefService)
- .getBranch("extension.realurl."),
-
- abort: function () {
- if (RealURL.timer) {
- clearTimeout(RealURL.timer)
- RealURL.timer = null
- }
- if (RealURL.request) {
- RealURL.request.abort()
- RealURL.request = null
- RealURL._status.label = RealURL.message("aborted")
- }
- },
-
- expand: function () {
- this.abort()
-
- // refresh display settings...
- for (var p in this.display) this.display[p] = this.pref.getBoolPref("display." + p)
-
- var url = window.gContextMenu?
- gContextMenu.getLinkURL? gContextMenu.getLinkURL() : gContextMenu.linkURL() // mostly
- : client.menuManager.contextFunction("context:messages", null).url // ChatZilla
-
- this._status.label = RealURL.message("expanding").replace(/#/, url)
- var req = new XMLHttpRequest, my = this
- req.open("GET", this.service.replace(/%/, url.replace(/.*:\/\//, "")), true)
- req.onload = function () {
- if (req.status == 200) {
- var rsp = JSON.parse(req.responseText), txt = "TheRealURL: "
- if (my.display.url) txt += rsp.url
- if (my.display.title) txt += (txt == ""? "" : " ") + '"' + rsp.title + '"'
- if (my.display.type || my.display.charset) txt += (txt == ""? "(" : " (")
- if (my.display.type) txt += rsp.headers["content-type"].replace(/;.*$/, "")
- if (my.display.type && my.display.charset) txt += "; "
- if (my.display.charset) txt += rsp.headers["content-type"].replace(/^[^;]*;\s+/, "")
- if (my.display.type || my.display.charset) txt += ")"
- if (my.display.size) txt += (txt == ""? "" : " ") + rsp.headers["content-length"]
- my._status.label = txt
- }
- else my._status.label = RealURL.message("cannot") + " (" + req.status + ")"
- }
- req.onerror = function () {
- my._status.label = RealURL.message("error")
- }
- req.send(null)
- this.timer = setTimeout(this.abort, 1000 * this.timeout)
- },
-
- load: function () {
- // prefs...
- RealURL.service = RealURL.pref.getCharPref("service.url")
- RealURL.timeout = RealURL.pref.getIntPref("service.timeout")
-
- // UI...
- RealURL._status = document.getElementById("statusbar-display") // Firefox
- || document.getElementById("statusText") // Thunderbird
- || document.getElementById("status-text") // ChatZilla
-
- RealURL._menuitem = document.getElementById("realurl-item")
- if (RealURL._menuitem.parentNode.localName == "overlaytarget") { // ChatZilla...
- document.getElementById("context:messages")
- .insertBefore(
- RealURL._menuitem.parentNode.removeChild(RealURL._menuitem),
- document.getElementById("context:messages:popup:usercommands")
- )
- }
-
- RealURL._menuitem.parentNode.addEventListener("popupshowing", RealURL.show, false)
- },
-
- message: function (key) {return this._menuitem.getAttribute(key)},
-
- show: function (event) {
- if (window.gContextMenu) // most places...
- with (gContextMenu) RealURL._menuitem.hidden = !onLink || onMailtoLink
- else { // ChatZilla...
- try {
- var url = client.menuManager.contextFunction("context:messages", null).url
- RealURL._menuitem.hidden = !url || url.indexOf("mailto:") == 0
- }
- catch (ex) {
- RealURL._menuitem.hidden = true
- }
- }
- }
-
- }
-
- addEventListener("load", RealURL.load, false)